package com.iwayin.core.dao.answer;

import java.util.List;

import com.iwayin.core.dao.BaseDAOImpl;
import com.iwayin.core.dataobject.AnswerDO;

public class AnswerDAOImpl extends BaseDAOImpl implements AnswerDAO {

	@Override
	public Long addAnswer(AnswerDO answer) {
		return (Long) this.executeInsert("AnswerDAO.addAnswer", answer);
	}

	@Override
	public List<AnswerDO> findAnswerByAskUserId(AnswerDO answer) {
		return this.executeQueryForList("AnswerDAO.findAnswerByAskUserId", answer);
	}

	@Override
	public void deleteAnswer(AnswerDO answer) {
		this.getSqlMapClientTemplate().delete("AnswerDAO.deleteAnswer", answer);

	}

	@Override
	public Integer deleteAnswerByAskId(Long askId) {
		return executeDelete("AnswerDAO.deleteAnswerByAskId", askId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AnswerDO> findAnswers(AnswerDO query) {
		return this.executeQueryForList("AnswerDAO.findAnswers", "AnswerDAO.findAnswers.count", query);
	}
	
	@Override
	public AnswerDO findAnswerByBody(AnswerDO query) {
		return (AnswerDO) queryForObject("AnswerDAO.findAnswerByBody", query);
	}

	@Override
	public void answerVoteCountPlusOne(Long answerId) {
		executeUpdate("AnswerDAO.answerVoteCountPlusOne", answerId);
	}

	@Override
	public void answerVoteCountDownOne(Long answerId) {
		executeUpdate("AnswerDAO.answerVoteCountDownOne", answerId);
	}
	@Override
	public AnswerDO findAnswerById(Long answerId) {
		return (AnswerDO) queryForObject("AnswerDAO.findAnswerById",answerId);
	}
}
